package com.wsx.ones.monitor.core.netty;

import com.wsx.ones.monitor.core.serialize.RpcSerializeProtocol;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;

import java.util.concurrent.ConcurrentHashMap;


/**
 * netty服务端的通道设置，连接各个句柄
 * 要求根据提供的序列化来设置不同的编码解码方法
 * Created by wangshuaixin on 17/2/7.
 */
public class PullChannelHandler extends ChannelInitializer<SocketChannel> {

    private RpcSerializeProtocol protocol;
    private ConcurrentHashMap<String, Object> rpcBeanMap;

    public PullChannelHandler(RpcSerializeProtocol protocol, ConcurrentHashMap<String, Object> rpcBeanMap) {
        this.protocol = protocol;
        this.rpcBeanMap = rpcBeanMap;
    }

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        PullPipelineFrame frame = new PullPipelineFrame();
        //设置通道句柄的核心操作方法
        frame.initPipeline(protocol, socketChannel.pipeline(), rpcBeanMap);
    }
}
